import scrapy

from scrapy_dytt8_35new.items import ScrapyDytt835NewItem


class MovieSpider(scrapy.Spider):
    name = "movie"
    allowed_domains = ["www.dytt8.net"]
    start_urls = ["https://www.dytt8.net/index2.htm"]

    def parse(self, response):

        movie_list = response.xpath('//div[@class="co_content8"]//tr//a[2]')
        for movie in movie_list:
            name = movie.xpath('./text()').extract_first()
            href = movie.xpath('./@href').extract_first()
            # 需要加上前面域名，不然下面请求不到
            url = 'https://www.dytt8.net' + href
            # print(name,url)
            yield scrapy.Request(url=url,callback=self.parse_second,meta={'name':name,'url':url})

    def parse_second(self,response):
        name = response.meta['name']
        href = response.meta['url']
        # print(name)
        src = response.xpath('//div[@id="Zoom"]//img/@src').extract_first()

        movie = ScrapyDytt835NewItem(name=name,src=src,href=href)

        yield movie




        pass
